<!--
 * @Description: '底部菜单栏'
 * @Date: 2021-07-11 22:26:52
 * @LastEditTime: 2021-12-08 00:15:07
 * @FilePath: \vue-test\src\components\TabBar.vue
-->
<template>
  <div class="tab-box">
    <!-- <component :is="currentComponent"></component> -->
    <scroll-tab :current-select="activeIndex" @selectChange="handleSelectChange">
    <transition
      name="bounce"
      enter-active-class="bounceInLeft"
      leave-active-class="bounceOutRight"
    >
      <router-view/>
    </transition>
    </scroll-tab>
    <div class='tab-bar'>
      <router-link :class="[activeIndex === index ? 'cur' : '','item']" v-for="(v, index) in TabList" :key='v.id' :to="v.link" @click="switchTo(index)">
        <span class="text">{{v.text}}</span>
      </router-link>
    </div>
  </div>
</template>
<script>

export default {
  name: 'TabBar',
  data () {
    return {
      currentComponent: 'Product',
      activeIndex: 0,
      TabList: [
        { link: '/product', className: '', text: '首页' },
        { link: '/category', className: '', text: '分类' },
        { link: '/cart', className: '', text: '购物车' },
        { link: '/center', className: '', text: '我的' }
      ],
      cartNum: 0
    }
  },
  created () {
    this.cartNum = this.$store.state.cartsNumber
  },
  methods: {
    // tab切换函数
    switchTo (i) {
      console.log('切换i', i)
      this.activeIndex = i
    },
    // 页面切换函数
    handleSelectChange (tabIndex) {
      this.activeIndex = tabIndex
    }
  }
}
</script>
<style lang="less" scoped>
/*tabbar导航样式*/
.tab-bar {
  position: fixed;
  left: 0;
  bottom: 0;
  z-index: 9999;
  width: 100%;
  height: 100px;
  background: #fff;
  border-top: 1px solid #dcdcdc;
  display: flex;
  justify-content: space-between;
  .item {
    width: 25%;
    text-align: center;
    font-size: 14px;
    color: #666;
    text-align: center;
    position: relative;
    span {
      display: block;
      line-height: 100px;
    }
  }
}
.bounce-enter-active,
.bounce-leave-active {
    transition: all 0.4s;
}

// .bounce-enter,
// .bounce-leave{
//     transform: translate3d(100%, 0, 0);
// }
// .fade-enter{ opacity:0;}
// .fade-leave{opacity:1;}
// .fade-enter-active{transition:opacity 0.5s;}
// .fade-leave-active{opacity:0; transition:opacity 0.5s;}
@keyframes bounceOutRight {
  20% {
    opacity: 1;
    transform: translate3d(-20px, 0, 0) scaleX(0.9);
  }

  to {
    opacity: 0;
    transform: translate3d(2000px, 0, 0) scaleX(2);
  }
}

.bounceOutRight {
  animation-name: bounceOutRight;
}
@keyframes bounceInLeft {
  from,
  60%,
  75%,
  90%,
  to {
    animation-timing-function: cubic-bezier(0.215, 0.61, 0.355, 1);
  }

  0% {
    opacity: 0;
    transform: translate3d(-3000px, 0, 0) scaleX(3);
  }

  60% {
    opacity: 1;
    transform: translate3d(25px, 0, 0) scaleX(1);
  }

  75% {
    transform: translate3d(-10px, 0, 0) scaleX(0.98);
  }

  90% {
    transform: translate3d(5px, 0, 0) scaleX(0.995);
  }

  to {
    transform: translate3d(0, 0, 0);
  }
}

.bounceInLeft {
  animation-name: bounceInLeft;
}
</style>
